package com.xx.pmis.persistence.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;

import com.xx.pmis.model.LuckyData;

public class LuckyDataDAOImpl extends BaseHibernateDAOImpl<LuckyData> implements LuckyDataDAO {

	public LuckyData getLuckyDataByLuckyDataID(String ldID) {
		LuckyData luckyData;
		try {
			luckyData = (LuckyData) getSession().get(LuckyData.class, ldID);

		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return luckyData;
	}

	@SuppressWarnings("unchecked")
	public List<LuckyData> getAllLuckyData() {
		List<LuckyData> luckyDatas;
		try {
			Query query = getSession().getNamedQuery("AllLuckyDataQuery");
			luckyDatas = query.list();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return luckyDatas;
	}
	
	public LuckyData getLuckyDataByIssueNumber(String issueNumber) {
		LuckyData luckyData;
		try {
			Query query = getSession().getNamedQuery("LuckyDataByIssueNumberQuery");
			query.setString("issueNumber", issueNumber);
			luckyData = (LuckyData) query.uniqueResult();
		} catch (HibernateException ex) {
			throw convertHibernateAccessException(ex);
		}
		return luckyData;
	}

}
